package com.etone.smartAudit.vo.auditException;

import com.etone.smartAudit.vo.PagerVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: 蒋学伟
 * @create: 2020-07-06 18:22:25
 * @Description AuditExceptionDetailVO
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Data
@ApiModel(value = "审计异常详情")
public class AuditExceptionDetailVO implements Serializable {

    @ApiModelProperty("表头信息")
    private List<AuditExceptionDetailHeadVO> head;

    @ApiModelProperty("数据")
    private PagerVO<Map<String, Object>> data;

    /**
     * 获取表头说明
     *
     * @return
     */
    public List<String> getHeadList() {
        return head.stream().map(headFlag -> headFlag.getHead()).collect(Collectors.toList());
    }

    /**
     * 获取表头字段
     *
     * @return
     */
    public List<String> getColumnList() {
        return head.stream().map(headFlag -> headFlag.getColumn()).collect(Collectors.toList());
    }

    /**
     * 获取数组数据
     *
     * @return
     */
    public List<List<String>> getDataList() {
        return data.getRows().stream().map(dataFlag -> {
            List<String> row = new ArrayList<>();
            head.forEach(head -> {
                Object cell = dataFlag.get(head.getColumn());
                row.add(cell == null ? "" : cell.toString());
            });
            return row;
        }).collect(Collectors.toList());
    }
}
